<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Result extends CI_Controller {

	private $_data = array();
	
	function __construct()
	{
		parent::__construct();
		$this->load->model(array('lich_model','location_model','result_model'));
		$this->_data['locations']	=	$this->location_model->get_all();
		$this->load->helper('result');
	}
	
	public function index()
	{
		$result	=	$this->result_model->get_today();
		
		$this->_data['data']	=	$result;
		$this->_data['tmpl']	=	'client/result/index';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	public function day()
	{
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$day	=	$this->input->post('day');
			$month	=	$this->input->post('month');
			$year	=	$this->input->post('year');
			$lid	=	$this->input->post('lid');
			
			$input_form['lid']		=	$lid;
			$input_form['day']		=	$day;
			$input_form['month']	=	$month;
			$input_form['year']		=	$year;
			$this->_data['input_form']	=	$input_form;
			
			if($day > 0 && $month > 0 && $year > 0)
			{
				$date	=	$year.'-'.$month.'-'.$day;
				$result	=	$this->result_model->get_many_by(array('date' => $date));
				
				foreach($result as $k => $v)
				{
					$city	=	$this->location_model->get_by(array('id' => $v->lid));
					$result[$k]->city_name	=	$city->name;
				}
				$this->_data['data']	=	$result;
				
			}
			
		}
		
		$this->_data['tmpl']	=	'client/result/day';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	public function locations()
	{
		$this->_data['tmpl']	=	'client/result/locations';
		$this->load->view('client/layout/content', $this->_data);
	}
	
	public function location()
	{
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			$day	=	$this->input->post('day');
			$month	=	$this->input->post('month');
			$year	=	$this->input->post('year');
			$lid	=	$this->input->post('lid');
			
			$input_form['lid']		=	$lid;
			$input_form['day']		=	$day;
			$input_form['month']	=	$month;
			$input_form['year']		=	$year;
			$this->_data['input_form']	=	$input_form;
			
			if($day > 0 && $month > 0 && $year > 0)
			{
				$date	=	$year.'-'.$month.'-'.$day;
				$this->_data['result']	=	$this->result_model->get_by(array('date' => $date,'lid' => $lid));
			}
			$location	=	$this->location_model->get_by('id',$lid);
			$this->_data['location']	=	$location;
			
		}
		$this->_data['tmpl']	=	'client/result/location';
		$this->load->view('client/layout/content', $this->_data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */